package base.thread_JUC2.chapter04.demo08;

import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);

        Task task = new Task();
        Future<String> future = pool.submit(task);

        // 延时2s让线程执行
        TimeUnit.SECONDS.sleep(2);

        future.cancel(true);

        System.out.println(future.isCancelled());
        System.out.println(future.isDone());

        pool.shutdown();
    }
}
